import fs from 'fs'
import async from 'async'
import { glob } from 'glob'


/**
 * 读取JSON文件
 */
function readJSON (jsonUrl) {
  return new Promise(async (resolve, reject) => {
    try {
      const jsfiles = await glob([jsonUrl]);
        for await (const fileUrl of jsfiles) {
          async.eachSeries([fileUrl], function (file, callback) {
              fs.readFile(file, "utf8", function (err, data) {
                if (err) {
                  return callback(err);
                }
                resolve(JSON.parse(data))
              });
            },
            function (err) {
              if (err) {
                console.log("一个错误:", err);
              }
            }
          );
        }
      } catch (error) {
        console.log("error- chucuo l", error);
        reject(error)
      }
  })
}


readJSON(`E:\\mine\\i18n_node\\i18n.json`).then(res => {
  console.log(res);
})
